/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.model;

import java.io.File;
import java.io.IOException;

import org.merak.core.Application;

public class Path {

	//~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private String path = null;
	private File   file = null;

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	public final void init(String path) {

		this.path = path;
		this.file = new File(this.path);

	}
	//****************************************************************************
	public final String getPath() {
		return this.path;
	}
	//****************************************************************************
	public final String getPath(String path) {

		return path != null
		       ? this.path + File.separatorChar + path
		       : this.path
		       ;
	}
	//****************************************************************************
	public final File getFile() {
		return this.file;
	}
	//****************************************************************************
	public final File[] listFiles() {
		return this.file.listFiles();
	}
	//****************************************************************************
	public final File getFile(String path) {

		return  path != null
				? new File(this.path + File.separatorChar + path)
				: this.file
				;

	}
	//****************************************************************************
	public final File createDirectory(String path) {
		return Application.io.createDirectory( this.getPath(path) );
	}
	//****************************************************************************
	public final File createFile(String path) throws IOException {

		File newFile = this.getFile(path);
		newFile.createNewFile();
		return newFile;

	}
	//****************************************************************************
	@Override
	public final String toString() {
		return this.path;
	}
	//****************************************************************************
}
